package com.zkx.action;

import com.zkx.method.GoddessMethod;
import com.zkx.model.Goddess;

import java.sql.SQLException;
import java.util.*;

public class GoddessAction {
    public static void main(String[] args) throws SQLException {
        //GoddessMethod gm1 = new GoddessMethod();
        //将查询的结果创建Goddess类型的对象，将对象放入创建的gs集合 selectGoddess()返回一个List<Goddess>类的集合gs
//        List<Goddess> gs = gm1.selectGoddess();
//        for(Goddess goddess: gs){
//            System.out.println(goddess.getUser_name()+","+goddess.getAge());
//        }


        GoddessMethod gm2 = new GoddessMethod();
        Goddess g1 = new Goddess();
        g1.setUser_name("小红");
        g1.setAge(27);
        g1.setSex(1);
        g1.setBirthday(new Date());
        g1.setEmail("xiaoli@imooc.com");
        g1.setMobile("15435345345");
        g1.setUpdate_user("tom");
        g1.setIsdel(1);
        g1.setId(2);
        //将新创建的Goddess对象属性初始化后，传到GoddessMethod的insertGoddess方法中
        //gm2.insertGoddess(g1);

        //gm2.updateGoddess(g1);
        //gm2.deleteGoddess(2);
        //Goddess gs1 = gm2.selectGoddess1(3);
        //System.out.println(gs1.toString());
        //Goddess gs1 = gm2.selectGoddess("小红");
        //System.out.println(gs1.toString());


        List<Map<String,Object>> params = new ArrayList<Map<String,Object>>();
        Map<String,Object> param = new HashMap<String,Object>();
        param.put("name","sex");
        param.put("rela","=");
        param.put("value","1");
        params.add(param);
        param.put("name","user_name");
        param.put("rela","like");
        param.put("value","'%丽%'");
        params.add(param);
        List<Goddess> result = gm2.selectGoddess(params);
        for(int i = 0;i<result.size();i++){
            System.out.println(result.get(i).toString());
        }
    }
    //添加
    public void insert(Goddess g) throws SQLException {
        GoddessMethod method = new GoddessMethod();
        method.insertGoddess(g);
    }
    //修改
    public void update(Goddess g) throws SQLException {
        GoddessMethod method = new GoddessMethod();
        method.updateGoddess(g);
    }
    //删除
    public void del(Integer id) throws SQLException {
        GoddessMethod method = new GoddessMethod();
        method.deleteGoddess(id);
    }
    //查询所有女神的简略信息
    public List<Goddess> select() throws SQLException {
        GoddessMethod method = new GoddessMethod();
        return method.selectGoddess();
    }
    //自定条件查询女神详细信息
    public List<Goddess> select(List<Map<String,Object>> params) throws SQLException {
        GoddessMethod method = new GoddessMethod();
        return method.selectGoddess(params);
    }
    //通过id查看某个女神详细信息
    public Goddess select1(Integer id) throws SQLException {
        GoddessMethod method = new GoddessMethod();
        return method.selectGoddess1(id);
    }
}
